package com.xczl.book.action.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shishuo.cms.entity.vo.JsonVo;
import com.shishuo.cms.entity.vo.PageVo;
import com.xczl.book.entity.Borrow;
import com.xczl.book.entity.vo.BorrowVo;
import com.xczl.book.service.BorrowService;

@Controller("bookAdminBorrowAction")
@RequestMapping("book/admin/borrow")
public class BorrowAction {

	@Autowired
	private BorrowService borrowService;

	@RequestMapping("index.htm")
	public String index(BorrowVo filter,
			@RequestParam(value = "p", defaultValue = "1") int pageNum,
			ModelMap model) {
		PageVo<BorrowVo> pageVo = borrowService
				.findByCondition(pageNum, filter);
		model.addAttribute("pageVo", pageVo);
		model.addAttribute("filter", filter);
		return "book/admin/borrow/index";
	}

	@RequestMapping("borrowPage.htm")
	public String borrowPage() {
		return "book/admin/borrow/borrow";
	}

	@ResponseBody
	@RequestMapping("borrow.json")
	public JsonVo<String> borrow(Borrow borrow) {
		borrow.setState(1);
		borrowService.add(borrow);
		JsonVo<String> json = new JsonVo<String>();// 返回给页面的对象
		json.check();
		return json;
	}

	@ResponseBody
	@RequestMapping("batchBorrow.json")
	public JsonVo<String> batchBorrow(int userId,
			@RequestParam(value = "bookIds[]") int[] bookIds) {
		borrowService.batchBorrow(userId, bookIds);
		JsonVo<String> json = new JsonVo<String>();
		json.check();
		return json;
	}
}
